/**
 * Copyright (c) 2007,中企动力华南研发中心<br>
 * All rights reserved.<br>
 */
package com.ce.pms.system.renovation.service.impl;

import java.util.List;

import com.ce.pms.base.service.impl.PmsBaseServiceImpl;
import com.ce.pms.charge.dao.IBusinessCodeDao;
import com.ce.pms.charge.model.BusinessCodeDomain;
import com.ce.pms.charge.service.IParameterDefService;
import com.ce.pms.charge.vo.ParameterDefVO;
import com.ce.pms.common.dao.ISysrefcodeDao;
import com.ce.pms.common.model.SysrefcodeDO;
import com.ce.pms.exception.BusinessException;
import com.ce.pms.system.renovation.service.IReturnConfigService;
import com.ce.util.BlankUtil;

/**
 * 功能描述：<br>
 * @author 易贤建 创建日期：2009-1-4<br>
 */
public class ReturnConfigServiceImpl extends PmsBaseServiceImpl implements
		IReturnConfigService {
	/**
	 * 系统参数DAO
	 */
	private ISysrefcodeDao sysrefcodeDao;
	/**
	 * 参数预设Service
	 */
	private IParameterDefService parameterDefService;
	/**
	 * 交易码DAO
	 */
	private IBusinessCodeDao businessCodeDao;

	/**
	 * 功能描述:获取装修审批时间设置DO<br>
	 * @return
	 * Create author:yixianjian <br>
	 * Create on:2009-1-4  <br>
	 */
	public SysrefcodeDO getSysrefcodeWithReturnconfig(){
		List<SysrefcodeDO> sysrefCodes = sysrefcodeDao.querySysrefCodesByCode(this.RM_FEE_RETURN_CONFIG);
		if(BlankUtil.isBlank(sysrefCodes) || sysrefCodes.size() != 1)
			throw new BusinessException("system:returnconfig_sysrefcode_not_found",BusinessException.ERROR);

		return sysrefCodes.get(0);
	}
	/**
	 * 功能描述:获取装修罚款交易码参数设置<br>
	 * @return
	 * Create author:yixianjian <br>
	 * Create on:2009-1-4  <br>
	 */
	public BusinessCodeDomain getBizcodeWithDeposit(){
		ParameterDefVO parameterDef = parameterDefService.findParameterDefByPkey(this.RENOVATE_AMERCEMENT_CODE);
		if(parameterDef == null || parameterDef.getPvalue() == null){
			throw new BusinessException("system:returnConfig_bizcode_error",BusinessException.ERROR);
		}
		Long buzKeyword = parameterDef.getPvalue();
		BusinessCodeDomain codeDomain =  businessCodeDao.findById(buzKeyword);
		if(codeDomain == null)
			throw new BusinessException("system:returnConfig_bizcode_notFount",BusinessException.ERROR);
		return codeDomain;
	}
	/**
	 * 功能描述: 更新复验天数<br>
	 * Create author:yixianjian <br>
	 * Create on:2009-1-6  <br>
	 */
	public void editReturnconfig(SysrefcodeDO returnConfig,Long depositKeyword){
		checkParameterIsNull(returnConfig.getValue(), "system:请输入装修复验结果通过天数");
		checkParameterIsNull(depositKeyword,"system:装修违规罚款对应交易码");
		SysrefcodeDO sysrefcode = sysrefcodeDao.findById(returnConfig.getId());
		sysrefcode.setValue(returnConfig.getValue());
		sysrefcodeDao.saveObject(sysrefcode);

		ParameterDefVO parameterDefVO = parameterDefService.findParameterDefByPkey("RENOVATE_AMERCEMENT_CODE");
		parameterDefVO.setPvalue(depositKeyword);
		parameterDefService.editParameterDef(parameterDefVO);

	}
	public void setSysrefcodeDao(ISysrefcodeDao sysrefcodeDao) {
		this.sysrefcodeDao = sysrefcodeDao;
	}
	public void setBusinessCodeDao(IBusinessCodeDao businessCodeDao) {
		this.businessCodeDao = businessCodeDao;
	}
	public void setParameterDefService(IParameterDefService parameterDefService) {
		this.parameterDefService = parameterDefService;
	}
}
